<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div class="box"></div>
    <script>
      // x是月份y是日期
      function clock(x, y) {
        var today = new Date();
        // console.log(today);
        //2024/8/1 00:00:00
        // 月份从0开始
        var setDate = new Date(2024, x - 1, y);

        // console.log(setDate);
        // console.log(setDate - today);
        var timeGap = setDate - today;
        var seconds = Math.floor(timeGap / 1000);
        var minutes = Math.floor(seconds / 60);
        var hours = Math.floor(minutes / 60);
        var days = Math.floor(hours / 24);
        hours %= 24;
        minutes %= 60;
        // seconds %= 60;
        var box = document.querySelector(".box");
        box.textContent = `距离${x}月${y}日后还有${days}天${hours}小时${minutes}分${seconds}秒`;
      }

      clock(8, 1);
      setInterval(() => {
        clock(8, 1);
      }, 1000);
    </script>
  </body>
</html>
